\subsection{Morphisms of ringed spaces}
Let \( (X, \mathcal O_X) \) be a scheme.
The stalks \( \mathcal O_{X,\mathfrak p} \) are local rings: they have a unique maximal ideal, which is the set of all non-unit elements.
Given \( f \in \mathcal O_X(U) \), we can meaningfully ask whether \( f \) vanishes at \( \mathfrak p \); that is, if the image of \( f \) in \( \mathcal O_{X, \mathfrak p} \) is contained in the maximal ideal.
\begin{definition}
    A morphism of ringed spaces \( f : (X, \mathcal O_X) \to (Y, \mathcal O_Y) \) consists of a continuous function \( f : X \to Y \) and a morphism \( f^\sharp : \mathcal O_Y \to f_\star \mathcal O_X \) between sheaves of rings on \( Y \).
\end{definition}
\( f^\sharp \) represents function composition with \( f^{-1} \), although the ring \( \mathcal O_X \) may not be a ring of functions.
It is possible to find a morphism \( (f, f^\sharp) \) between schemes \( (X, \mathcal O_X) \) and \( (Y, \mathcal O_Y) \) such that there exists \( q \in U \subseteq Y \) and \( h \in \mathcal O_Y(U) \) such that \( h \) vanishes at \( q \) but \( f^\sharp(h) \in \mathcal O_X(f^{-1}(U)) \) does not vanish at some \( p \in X \) with \( f(p) = q \).
This motivates the definition of a morphism of schemes.

Let \( f : X \to Y \) be a morphism of ringed spaces.
Given any point \( p \in X \), there is an induced map \( f^\sharp : \mathcal O_{Y,f(p)} \to \mathcal O_{X,p} \).
Explicitly, given \( s \in \mathcal O_{Y,f(p)} \), we can represent it by \( (s_U, U) \) where \( U \) is open, \( f(p) \in U \), and \( s_U \in \mathcal O_Y(U) \).
Now, \( f^\sharp(s_U) \in \mathcal O_X(f^{-1}(U)) \), so the pair \( (f^\sharp(s_U), f^{-1}(U)) \) defines an element of \( \mathcal O_{X,p} \).
\begin{definition}
    A ringed space \( (X, \mathcal O_X) \) is called a \emph{locally ringed space} if for all \( p \in X \), the stalk \( \mathcal O_{X,p} \) is is a local ring.
    A morphism of locally ringed spaces \( (f, f^\sharp) : (X, \mathcal O_X) \to (Y, \mathcal O_Y) \) is a morphism of ringed spaces such that if \( \mathfrak m_p \) denotes the maximal ideal in \( \mathcal O_{X,p} \), then \( f^\sharp(\mathfrak m_{f(p)}) \subseteq \mathfrak m_p \).
\end{definition}
This encapsulates the idea that functions vanishing on the codomain must also vanish on the domain after the inverse image, as the maximal ideal represents functions vanishing at the point.

\subsection{Morphisms of schemes}
Note that all schemes are locally ringed spaces.
\begin{definition}
    A \emph{morphism of schemes} \( X \to Y \) is a morphism of locally ringed spaces \( X \to Y \).
\end{definition}
\begin{theorem}
    There is a natural bijection
    \[ \qty{\text{morphisms of schemes } \Spec B \to \Spec A} \leftrightarrow \qty{\text{homomorphisms of rings } A \to B} \]
\end{theorem}
\begin{proof}
    First, recall that a section \( s \) of a sheaf \( \mathcal F \) on \( U \) is a coherent collection of elements of the stalks \( s(p) \in \mathcal F_p \) for all \( p \in U \).
    We will construct a map of schemes \( \Spec B \to \Spec A \) for every ring homomorphism \( A \to B \), and then show that every morphism of schemes arises in this way.

    Let \( \varphi : A \to B \) be a ring homomorphism.
    Let \( \varphi^{-1} : \Spec B \to \Spec A \) be the map of topological spaces; this is a continuous function.
    We now build
    \[ \varphi^\sharp : \mathcal O_{\Spec A} \to \varphi_\star^{-1} \mathcal O_{\Spec B} \]
    At the level of stalks, the map \( A_{\varphi^{-1}(\mathfrak p)} \to B_{\mathfrak p} \) is induced by \( \varphi \) by mapping \( \frac{a}{s} \) to \( \frac{\varphi(a)}{\varphi(s)} \).
    This is well-defined, as for \( s \notin \varphi^{-1}(\mathfrak p) \), then \( \varphi(s) \notin \mathfrak p \).
    Observe that this is automatically a local homomorphism.
    
    We must now show that this choice of maps on stalks extends to a map between sheaves.
    Given \( U \subseteq \Spec A \), we need to define
    \[ \varphi^\sharp : \mathcal O_{\Spec A}(U) \to \mathcal O_{\Spec B}((\varphi^{-1})^{-1}(U)) \]
    An element \( s \in \mathcal O_{\Spec A}(U) \) is a collection of assignments \( (\mathfrak p \mapsto s(\mathfrak p))_{\mathfrak p \in U} \) for \( \mathfrak p \in U \) and \( s(\mathfrak p) \in A_{\mathfrak p} \).
    We then define \( \varphi^\sharp \) by
    \[ (\mathfrak p \mapsto s(\mathfrak p))_{\mathfrak p \in U} \mapsto (\mathfrak q \mapsto \varphi_{\mathfrak q}(s(\varphi^{-1}(\mathfrak q))))_{\mathfrak q \in (\varphi^{-1})^{-1}(U)} \]
    One can check that the gluing conditions are satisfied.

    Conversely, suppose \( (f, f^\sharp) : \Spec B \to \Spec A \) is a morphism of schemes.
    Using the fact that we have a map of global sections \( \mathcal O_{\Spec A}(\Spec A) \to \mathcal O_{\Spec B}(\Spec B) \), we obtain a ring homomorphism \( g : A \to B \).
    We must check that \( g^{-1} : \Spec B \to \Spec A \) gives the correct map \( f \) on topological spaces, and that the construction above yields the correct map \( f^\sharp \) on sheaves.
    The maps on stalks are compatible with restriction, so the following diagram commutes for all \( \mathfrak p \in \Spec B \).
    % https://q.uiver.app/#q=WzAsNCxbMCwwLCJcXEdhbW1hKFxcU3BlYyBBLCBcXG1hdGhjYWwgT197XFxTcGVjIEF9KSJdLFsxLDAsIlxcR2FtbWEoXFxTcGVjIEIsIFxcbWF0aGNhbCBPX3tcXFNwZWMgQn0pIl0sWzEsMSwiXFxtYXRoY2FsIE9fe1xcU3BlYyBCLCBcXG1hdGhmcmFrIHB9Il0sWzAsMSwiXFxtYXRoY2FsIE9fe1xcU3BlYyBBLCBmKFxcbWF0aGZyYWsgcCl9Il0sWzAsMV0sWzEsMl0sWzAsM10sWzMsMl1d
\[\begin{tikzcd}
	{\Gamma(\Spec A, \mathcal O_{\Spec A})} & {\Gamma(\Spec B, \mathcal O_{\Spec B})} \\
	{\mathcal O_{\Spec A, f(\mathfrak p)}} & {\mathcal O_{\Spec B, \mathfrak p}}
	\arrow[from=1-1, to=1-2]
	\arrow[from=1-2, to=2-2]
	\arrow[from=1-1, to=2-1]
	\arrow[from=2-1, to=2-2]
\end{tikzcd}\]
    Equivalently, the following diagram commutes for all \( \mathfrak p \in \Spec B \).
    % https://q.uiver.app/#q=WzAsNCxbMCwwLCJBIl0sWzEsMCwiQiJdLFsxLDEsIkJfe1xcbWF0aGZyYWsgcH0iXSxbMCwxLCJBX3tmKFxcbWF0aGZyYWsgcCl9Il0sWzAsMV0sWzEsMl0sWzAsM10sWzMsMl1d
\[\begin{tikzcd}
	A & B \\
	{A_{f(\mathfrak p)}} & {B_{\mathfrak p}}
	\arrow[from=1-1, to=1-2]
	\arrow[from=1-2, to=2-2]
	\arrow[from=1-1, to=2-1]
	\arrow[from=2-1, to=2-2]
\end{tikzcd}\]
    Since the morphism is local, \( (f^\sharp)^{-1}(\mathfrak p B_{\mathfrak p}) = f(\mathfrak p) A_{f(\mathfrak p)} \).
    As the above diagram commutes, \( g^{-1} = f \) as maps of topological spaces, and the maps of structure sheaves agree at the level of stalks by construction so they must agree everywhere.
\end{proof}

\subsection{Immersions}
\begin{definition}
    Let \( X, Y \) be schemes.
    A morphism of schemes \( f : X \to Y \) is an \emph{open immersion} if \( f \) induces an isomorphism of \( X \) onto an open subscheme \( \qty(U, \eval{\mathcal O_Y}_U) \) of \( Y \).
    A morphism \( f : X \to Y \) is a \emph{closed immersion} if \( f \) is a homeomorphism onto a closed subset of \( Y \), and \( g^\sharp : \mathcal O_Y \to g_\star \mathcal O_X \) is surjective.
\end{definition}
\begin{example}
    Let \( k[t] \to \faktor{k[t]}{(t^2)} \).
    The induced map \( \Spec \faktor{k[t]}{(t^2)} \to \Spec k[t] \) is a closed immersion.
    More generally, let \( A \) be a ring and \( I \) be an ideal in \( A \).
    Then the induced map \( \Spec \faktor{A}{I} \to \Spec A \) is a closed immersion.
\end{example}
\begin{definition}
    Let \( Y \) be a scheme.
    A \emph{closed subscheme} of \( Y \) is an equivalence class of closed immersions \( X \to Y \), where we say \( f : X \to Y \) and \( f' : X' \to Y \) are equivalent if there is a commutative triangle
    % https://q.uiver.app/#q=WzAsMyxbMCwwLCJYIl0sWzIsMCwiWCciXSxbMSwxLCJZIl0sWzAsMSwiXFxzaW0iLDAseyJzdHlsZSI6eyJ0YWlsIjp7Im5hbWUiOiJhcnJvd2hlYWQifX19XSxbMSwyLCJmJyJdLFswLDIsImYiLDJdXQ==
\[\begin{tikzcd}
	X && {X'} \\
	& Y
	\arrow["\sim", tail reversed, from=1-1, to=1-3]
	\arrow["{f'}", from=1-3, to=2-2]
	\arrow["f"', from=1-1, to=2-2]
\end{tikzcd}\]
\end{definition}

\subsection{Fibre products}
The notion of fibre product will simultaneously generalise the notions of product, intersections of closed subschemes, and inverse images of subschemes (such as points) along morphisms.
\begin{definition}
    Consider a diagram
    % https://q.uiver.app/#q=WzAsMyxbMSwwLCJYIl0sWzEsMSwiUyJdLFswLDEsIlkiXSxbMCwxXSxbMiwxXV0=
\[\begin{tikzcd}
	& X \\
	Y & S
	\arrow[from=1-2, to=2-2]
	\arrow[from=2-1, to=2-2]
\end{tikzcd}\]
    The \emph{fibre product} is a scheme \( X \times_S Y \) making the following diagram commute:
    % https://q.uiver.app/#q=WzAsNCxbMSwwLCJYIl0sWzEsMSwiUyJdLFswLDEsIlkiXSxbMCwwLCJYIFxcdGltZXNfUyBZIl0sWzAsMV0sWzIsMV0sWzMsMiwicF9ZIiwyXSxbMywwLCJwX1giXV0=
\[\begin{tikzcd}
	{X \times_S Y} & X \\
	Y & S
	\arrow[from=1-2, to=2-2]
	\arrow[from=2-1, to=2-2]
	\arrow["{p_Y}"', from=1-1, to=2-1]
	\arrow["{p_X}", from=1-1, to=1-2]
\end{tikzcd}\]
    such that for any other scheme \( Z \) together with morphisms \( q_X, q_Y \) completing the square, there is a unique factorisation through \( X \times_S Y \), making the following diagram commute.
    % https://q.uiver.app/#q=WzAsNSxbMiwxLCJYIl0sWzIsMiwiUyJdLFsxLDIsIlkiXSxbMSwxLCJYIFxcdGltZXNfUyBZIl0sWzAsMCwiWiJdLFswLDFdLFsyLDFdLFszLDIsInBfWSJdLFszLDAsInBfWCIsMl0sWzQsMCwicV9YIiwwLHsiY3VydmUiOi0yfV0sWzQsMiwicV9ZIiwyLHsiY3VydmUiOjJ9XSxbNCwzLCIiLDEseyJzdHlsZSI6eyJib2R5Ijp7Im5hbWUiOiJkYXNoZWQifX19XV0=
\[\begin{tikzcd}
	Z \\
	& {X \times_S Y} & X \\
	& Y & S
	\arrow[from=2-3, to=3-3]
	\arrow[from=3-2, to=3-3]
	\arrow["{p_Y}", from=2-2, to=3-2]
	\arrow["{p_X}"', from=2-2, to=2-3]
	\arrow["{q_X}", curve={height=-12pt}, from=1-1, to=2-3]
	\arrow["{q_Y}"', curve={height=12pt}, from=1-1, to=3-2]
	\arrow[dashed, from=1-1, to=2-2]
\end{tikzcd}\]
\end{definition}
Note that as this is a definition by universal property, if \( X \times_S Y \) exists, it is unique up to unique isomorphism.
The fibre product is schemes is the category-theoretic \emph{pullback}.
\begin{example}
    \begin{enumerate}
        \item In the category of sets, the fibre product of the diagram
        % https://q.uiver.app/#q=WzAsMyxbMSwwLCJYIl0sWzEsMSwiUyJdLFswLDEsIlkiXSxbMCwxLCJyX1giXSxbMiwxLCJyX1kiLDJdXQ==
    \[\begin{tikzcd}
        & X \\
        Y & S
        \arrow["{r_X}", from=1-2, to=2-2]
        \arrow["{r_Y}"', from=2-1, to=2-2]
    \end{tikzcd}\]
        is the set
        \[ X \times_S Y = \qty{(x, y) \in X \times Y \mid r_X(x) = r_Y(y)} \]
        \item In the category of topological spaces, the fibre product is defined to be the same set, assigning \( X \times_S Y \) the subspace topology as a subset of \( X \times Y \).
        \item Let \( r_X : X \to S \) be a map of sets, and let \( Y = \qty{\star} \) with \( r_Y(\star) = s \in S \).
        Then
        \[ X \times_S Y = r_X^{-1}(s) \]
        \item Let \( r_X : X \to S \) and \( r_Y : Y \to S \) be inclusions of subsets.
        Then
        \[ X \times_S Y = X \cap Y \]
    \end{enumerate}
\end{example}
\begin{theorem}
    Fibre products of schemes exist.
\end{theorem}
\begin{proof}[Proof sketch]
    \emph{Step 1.}
    Let \( X, Y, S \) be affine schemes, with associated rings \( A, B, R \).
    Then the fibre product \( X \times_S Y \) exists, and is isomorphic to \( \Spec (A \otimes_R B) \).
    Note that the tensor product is the category-theoretic pushout in the category of rings.
    We must now check that the universal property of the fibre product is satisfied.
    Consider the commutative square
    % https://q.uiver.app/#q=WzAsNCxbMCwwLCJaIl0sWzEsMCwiWCJdLFsxLDEsIlMiXSxbMCwxLCJZIl0sWzAsMV0sWzEsMl0sWzAsM10sWzMsMl1d
\[\begin{tikzcd}
	Z & X \\
	Y & S
	\arrow[from=1-1, to=1-2]
	\arrow[from=1-2, to=2-2]
	\arrow[from=1-1, to=2-1]
	\arrow[from=2-1, to=2-2]
\end{tikzcd}\]
    If \( Z \) is an affine scheme, the result holds.
    It is a general fact that a map of schemes \( Z \to \Spec (A \otimes_R B) \) is the same data as a map \( A \otimes_R B \to \Gamma(Z, \mathcal O_Z) \).

    \emph{Step 2.}
    Let \( X, Y, S \) be arbitrary schemes.
    If \( X \times_S Y \) exists and \( U \subseteq X \) is an open subscheme, then \( U \times_S Y \) also exists, by taking the inverse image of \( U \) under the projection \( X \times_S Y \to X \) endowed with the structure of an open subscheme.

    \emph{Step 3.}
    If \( X \) is covered by open subschemes \( \qty{X_i} \), then if \( X_i \times_S Y \) exists for all \( i \), then \( X \times_S Y \) exists, by gluing each of the \( X_i \times_S Y \) together.
    Note that the ability to glue these schemes together relies on Step 2, and the fact that there is no cocycle condition.

    \emph{Step 4.}
    If \( Y \) and \( S \) are affine, then \( X \times_S Y \) exists by Step 3, by covering \( X \) by affine subschemes.
    As \( X \) and \( Y \) are interchangeable, \( X \times_S Y \) exists for any \( X \) and \( Y \) as long as \( S \) is affine.

    \emph{Step 5.}
    Now, cover \( S \) by affine subschemes \( \qty{S_i} \).
    Let \( X_i, Y_i \) be the preimages of of \( S_i \) in \( X \) and \( Y \) respectively.
    Now, \( X_i \times_{S_i} Y_i \) exists.
    Observe by the universal property that \( X_i \times_{S_i} Y_i = X_i \times S Y_i \).
    Finally, gluing gives \( X \times_S Y \) as required. 
\end{proof}
\begin{example}
    \begin{enumerate}
        \item We have
        \[ \mathbb P^n_{\mathbb C} = \mathbb P^n_{\mathbb Z} \times_{\Spec \mathbb Z} \Spec \mathbb C \]
        where the map \( \Spec \mathbb C \to \Spec \mathbb Z \) is induced by the ring homomorphism \( \mathbb Z \to \mathbb C \), and the map \( \mathbb P^n_{\mathbb Z} \to \Spec \mathbb Z \) is induced locally by the inclusion \( \mathbb Z \to \mathbb Z\qty[\frac{x_0}{x_i}, \dots, \frac{x_n}{x_i}] \).
        Note also that
        \[ \mathbb Z[\vb x] \otimes_{\mathbb Z} \mathbb C = \mathbb C[\vb x] \]
        \item Let \( C = \Spec \faktor{\mathbb C[x, y]}{(y - x^2)} \) and \( L = \Spec \faktor{\mathbb C[x, y]}{(y)} \).
        We have natural closed immersions \( C \to \mathbb A^2_{\mathbb C} \) and \( L \to \mathbb A^2_{\mathbb C} \).
        One can show that
        \[ C \times_{\mathbb A^2_{\mathbb C}} L = \Spec \faktor{\mathbb C[x]}{(x^2)} \]
        representing the intersection.
    \end{enumerate}
\end{example}

\subsection{Schemes over a base}
In scheme theory, we often fix a scheme \( S \) called the \emph{base scheme}, and consider other schemes with a fixed map to \( S \).
These form a category of schemes \emph{over \( S \)}, where the morphisms are the morphisms of schemes \( f : X \to Y \) such that the following diagram commutes.
% https://q.uiver.app/#q=WzAsMyxbMCwwLCJYIl0sWzEsMSwiUyJdLFsyLDAsIlkiXSxbMCwxXSxbMCwyLCJmIl0sWzIsMV1d
\[\begin{tikzcd}
	X && Y \\
	& S
	\arrow[from=1-1, to=2-2]
	\arrow["f", from=1-1, to=1-3]
	\arrow[from=1-3, to=2-2]
\end{tikzcd}\]
This is known as Grothendieck's \emph{relative point of view}.
Typically, \( S \) is the spectrum of a field or a ring.
Note that every scheme has a unique morphism to \( \Spec \mathbb Z \), so the category of schemes is isomorphic to the category of schemes over \( \Spec \mathbb Z \).
The product of \( X \) and \( Y \) in the category of schemes over \( S \) is the fibre product \( X \times_S Y \).
Analogously, in commutative algebra, we often consider algebras of a fixed ring, and the category of rings is isomorphic to the category of \( \mathbb Z \)-algebras.

% TODO: Define reduced, integral, irreducible, noetherian... from ES2/Hartshorne

\subsection{Separatedness}
Recall that a topological space \( X \) is Hausdorff if and only if the diagonal \( \Delta_X \subseteq X \times X \) is closed.
\begin{definition}
    Let \( X \to S \) be a morphism of schemes.
    Then the \emph{diagonal} is the morphism \( \Delta_{X/S} : X \to X \times_S X \) induced using the universal property by the following diagram.
    % https://q.uiver.app/#q=WzAsNSxbMCwwLCJYIl0sWzEsMSwiWCBcXHRpbWVzX1MgWCJdLFsyLDEsIlgiXSxbMiwyLCJTIl0sWzEsMiwiWCJdLFswLDEsIiIsMCx7InN0eWxlIjp7ImJvZHkiOnsibmFtZSI6ImRhc2hlZCJ9fX1dLFsxLDJdLFsyLDNdLFsxLDRdLFs0LDNdLFswLDIsIlxcaWRfWCIsMCx7ImN1cnZlIjotMn1dLFswLDQsIlxcaWRfWCIsMix7ImN1cnZlIjoyfV1d
\[\begin{tikzcd}
	X \\
	& {X \times_S X} & X \\
	& X & S
	\arrow[dashed, from=1-1, to=2-2]
	\arrow[from=2-2, to=2-3]
	\arrow[from=2-3, to=3-3]
	\arrow[from=2-2, to=3-2]
	\arrow[from=3-2, to=3-3]
	\arrow["{\id_X}", curve={height=-12pt}, from=1-1, to=2-3]
	\arrow["{\id_X}"', curve={height=12pt}, from=1-1, to=3-2]
\end{tikzcd}\]
\end{definition}
We write \( \Delta \) for \( \Delta_{X/S} \) if \( X \) and \( S \) are clear from context.
\begin{remark}
    If \( U, V \) are open subschemes of \( X \) and \( S = \Spec k \) for a field \( k \), then
    \[ \Delta^{-1}(U \times_S V) = U \cap V \]
\end{remark}
\begin{definition}
    A morphism \( X \to S \) is \emph{separated} if \( \Delta_{X/S} : X \to X \times_S X \) is a closed immersion.
\end{definition}
\begin{example}
    Let \( X = \Spec \mathbb C[t] \), let \( S = \Spec \mathbb C \), and induce the map \( X \to S \) by the \( \mathbb C \)-algebra homomorphism \( \mathbb C \to \mathbb C[t] \).
    Then
    \[ X \times_S X = \Spec(\mathbb C[t] \otimes_{\mathbb C} \mathbb C[t]) \]
    and the diagonal map \( \Delta \) is induced by the multiplication map
    \[ \mathbb C[t] \otimes_{\mathbb C} \mathbb C[t] \to \mathbb C[t] \]
    Note that \( \Delta \) is closed, as the map \( \mathbb C[t] \otimes_{\mathbb C} \mathbb C[t] \to \mathbb C[t] \) is surjective.
\end{example}
\begin{proposition}
    Let \( g : X \to S \) be a morphism of schemes.
    Then there is a factorisation of \( \Delta_{X/S} \) as follows.
    % https://q.uiver.app/#q=WzAsMyxbMCwxLCJYIl0sWzEsMCwiVSJdLFsyLDEsIlggXFx0aW1lc19TIFgiXSxbMCwxLCJcXHRleHR7Y2xvc2VkIGltbWVyc2lvbn0iXSxbMSwyLCJcXHRleHR7b3BlbiBpbW1lcnNpb259Il0sWzAsMiwiXFxEZWx0YV97WC9TfSIsMl1d
\[\begin{tikzcd}
	& U \\
	X && {X \times_S X}
	\arrow["{\text{closed immersion}}", from=2-1, to=1-2]
	\arrow["{\text{open immersion}}", from=1-2, to=2-3]
	\arrow["{\Delta_{X/S}}"', from=2-1, to=2-3]
\end{tikzcd}\]
    We say that \( g : X \to S \) is a \emph{locally closed immersion}.
\end{proposition}
\begin{proof}
    Let \( S \) be covered by open affine subschemes \( \qty{V_i} \), and suppose \( X \) is covered by open affine subschemes \( \qty{U_{ij}} \), where for some fixed \( i \), the \( U_{ij} \) cover \( g^{-1}(V_i) \).
    We have morphisms \( U_{ij} \to V_i \) induced by
    % https://q.uiver.app/#q=WzAsNSxbMCwwLCJVX3tpan0iXSxbMSwwLCJnXnstMX0oVl9pKSJdLFsyLDAsIlZfaSJdLFsyLDEsIlMiXSxbMSwxLCJYIl0sWzAsMV0sWzEsMl0sWzIsM10sWzEsNF0sWzQsM11d
\[\begin{tikzcd}
	{U_{ij}} & {g^{-1}(V_i)} & {V_i} \\
	& X & S
	\arrow[from=1-1, to=1-2]
	\arrow[from=1-2, to=1-3]
	\arrow[from=1-3, to=2-3]
	\arrow[from=1-2, to=2-2]
	\arrow[from=2-2, to=2-3]
\end{tikzcd}\]
    where the commutative square is a fibre product.
    Observe that \( U_{ij} \times_{V_i} U_{ij} \) is affine and open in \( X \times_S X \), and their union contains the image of the diagonal \( \Delta_{X/S} \).
    Also,
    \[ \Delta^{-1}(U_{ij} \times_{V_i} U_{ij}) = U_{ij} \subseteq X \]
    Let \( U \) be the union of the \( U_{ij} \times_{V_i} U_{ij} \) over all \( i, j \).
    Then the second map in the statement is clearly an open immersion.
    Observe that to check if \( f : T \to T' \) is a closed immersion, it suffices to check locally on the codomain.
    For each \( U_{ij} \), the diagonal is a map \( U_{ij} \to U_{ij} \times_{V_i} U_{ij} \), which one can show is a closed immersion.
\end{proof}
\begin{proposition}
    If \( X \to S \) is a morphism of affine schemes, then \( \Delta_{X/S} \) is a closed immersion.
\end{proposition}
\begin{proof}
    Let \( X = \Spec A, S = \Spec B \), and let the map \( X \to S \) be given by a map \( B \to A \).
    Then the map \( A \otimes_B A \to A \) is surjective as required.
\end{proof}
Thus every morphism of affine schemes is separated.
\begin{corollary}
    Let \( X \to S \) be a morphism of schemes.
    If the image of \( \Delta_{X/S} \) is closed as a topological subspace, then \( X \to S \) is separated.
\end{corollary}
\begin{proof}
    A locally closed immersion onto a closed subset is a closed immersion.
\end{proof}
\begin{example}
    \begin{enumerate}
        \item Recall the bug-eyed line
        \[ \faktor{\mathbb A^1_k \sqcup \mathbb A^1_k} {\sim} \]
        where if \( U = \mathbb A^1_k \setminus \qty{0} \subseteq \mathbb A^1_k \) and \( V \) is defined similarly, we define the isomorphism \( V \to U \) by the map \( u \mapsto t : k[u,u^{-1}] \to k[t,t^{-1}] \).
        We claim that the bug-eyed line is not separated over \( \Spec k \).
        We can compute \( X \times_S X \) by the gluing construction of the fibre product.
        This is a plane with doubled axes and four origins.
        The diagonal only contains two of the four origins, and this is not a closed subset.
        \item Open and closed immersions are are always separated.
        \item All monomorphisms are separated.
        \item Compositions of separated morphisms are separated.
        \item Suppose \( X \to S \) is separated and \( S' \to S \) is an embedding.
        Then the map \( X \times_S S' \to S' \) that comes from
        % https://q.uiver.app/#q=WzAsNCxbMCwwLCJYIFxcdGltZXNfUyBTJyJdLFsxLDAsIlgiXSxbMSwxLCJTIl0sWzAsMSwiUyciXSxbMCwxXSxbMSwyXSxbMCwzXSxbMywyXV0=
\[\begin{tikzcd}
	{X \times_S S'} & X \\
	{S'} & S
	\arrow[from=1-1, to=1-2]
	\arrow[from=1-2, to=2-2]
	\arrow[from=1-1, to=2-1]
	\arrow[from=2-1, to=2-2]
\end{tikzcd}\]
        is also separated.
        This is called a \emph{base extension}: the right-hand side of the diagram is the original morphism \( X \to S \), and the left-hand side can be thought of as the same morphism under a base change.
    \end{enumerate}
\end{example}
\begin{proposition}
    Let \( R \) be a ring.
    The morphism \( \mathbb P^n_R \to \Spec R \) is separated.
\end{proposition}
\begin{proposition}
    We want to show that the map \( \Delta \) in the following diagram is closed, where the commutative square is a fibre product.
    % https://q.uiver.app/#q=WzAsNSxbMCwwLCJcXG1hdGhiYiBQXm5fUiJdLFsxLDAsIlxcbWF0aGJiIFBebl9SIFxcdGltZXNfUiBcXG1hdGhiYiBQXm5fUiJdLFsxLDEsIlxcbWF0aGJiIFBebl9SIl0sWzIsMCwiXFxtYXRoYmIgUF5uX1IiXSxbMiwxLCJcXFNwZWMgUiJdLFswLDEsIlxcRGVsdGEiXSxbMSwyXSxbMSwzXSxbMyw0XSxbMiw0XV0=
\[\begin{tikzcd}
	{\mathbb P^n_R} & {\mathbb P^n_R \times_R \mathbb P^n_R} & {\mathbb P^n_R} \\
	& {\mathbb P^n_R} & {\Spec R}
	\arrow["\Delta", from=1-1, to=1-2]
	\arrow[from=1-2, to=2-2]
	\arrow[from=1-2, to=1-3]
	\arrow[from=1-3, to=2-3]
	\arrow[from=2-2, to=2-3]
\end{tikzcd}\]
    It suffices to check this result on an open cover of \( \mathbb P^n_R \times_R \mathbb P^n_R \).
    Let \( A = R[x_0, \dots, x_n] \) with the usual grading, so \( \Proj A = \mathbb P^n_R \).
    Then let \( U_i = \Spec \qty(A\qty[\frac{1}{x_i}])_0 \).
    These \( U_i \) form an open cover of \( \mathbb P^n_R \).
    Now,
    \[ U_i \times_R U_j = \Spec R\qty[\frac{x_0}{x_i}, \dots, \frac{x_n}{x_i}, \frac{y_0}{y_j}, \dots, \frac{y_n}{y_j}] \]
    Observe that the restriction of \( \Delta \) to \( \Delta^{-1}(U_i \times_R U_j) \) is
    \[ U_i \cap U_j \to U_i \times_R U_j \]
    given on rings by the map
    \[ R\qty[\frac{x_0}{x_i}, \dots, \frac{x_n}{x_j}]\qty[\frac{x_i}{x_j}] \leftarrow R\qty[\frac{x_0}{x_i}, \dots, \frac{x_n}{x_i}, \frac{y_0}{y_j}, \dots, \frac{y_n}{y_j}] \]
    by changing \( y_k \) into \( x_k \).
    This is surjective, and the \( U_i \times_R U_j \) cover \( \mathbb P^n_R \times_R \mathbb P^n_R \), so \( \Delta \) is closed.
\end{proposition}
\begin{definition}
    Let \( k = \overline k \) be an algebraically closed field.
    Let \( X \to \Spec k \) be a scheme over \( \Spec k \).
    We say that \( X \) is of \emph{finite type} over \( \Spec k \) if there is a cover of \( X \) by affines \( \qty{U_\alpha}_\alpha \) such that \( \mathcal O_X(U_\alpha) \) is finitely generated \( k \)-algebra.
    We say that \( X \) is \emph{reduced} if for all open \( U \subseteq X \), \( \mathcal O_X(U) \) has no nilpotent elements.
\end{definition}
\begin{definition}
    A morphism \( X \to \Spec k \) is a \emph{variety} if it is reduced, of finite type, and separated.
\end{definition}

\subsection{Properness}
\begin{definition}
    Let \( f : X \to S \) be a morphism.
    Then \( f \) is of \emph{finite type} if there exists an affine cover of \( S \) by open \( \qty{V_\alpha}_\alpha \) where \( V_\alpha = \Spec A_\alpha \), and covers \( \qty{U_{\alpha\beta}}_\beta \) of \( f^{-1}(V_\alpha) \) by open affine subschemes with \( U_{\alpha\beta} = \Spec B_{\alpha\beta} \), such that \( B_{\alpha\beta} \) is a finitely generated \( A_\alpha \)-algebra, and \( \qty{U_\alpha\beta}_{\beta} \) can be chosen to be finite.
\end{definition}
\begin{definition}
    A moprhism \( f : X \to S \) is \emph{closed} if it is closed as a map of topological spaces.
    It is \emph{universally closed} if for any \( S' \to S \), the induced map \( X \times_S S' \to S' \) is also closed.
    \( f \) is \emph{proper} if it is separated, of finite type, and universally closed.
\end{definition}
\begin{example}
    \begin{enumerate}
        \item Closed immersions are proper.
        \item The obvious map \( \mathbb A^1_k \to \Spec k \) is not proper, because it is not universally closed.
        Indeed, consider the fibre product
        % https://q.uiver.app/#q=WzAsNCxbMCwwLCJcXG1hdGhiYiBBXjJfayJdLFsxLDAsIlxcbWF0aGJiIEFeMV9rIl0sWzEsMSwiXFxTcGVjIGsiXSxbMCwxLCJcXG1hdGhiYiBBXjFfayJdLFswLDFdLFsxLDJdLFswLDNdLFszLDJdXQ==
\[\begin{tikzcd}
	{\mathbb A^2_k} & {\mathbb A^1_k} \\
	{\mathbb A^1_k} & {\Spec k}
	\arrow[from=1-1, to=1-2]
	\arrow[from=1-2, to=2-2]
	\arrow[from=1-1, to=2-1]
	\arrow[from=2-1, to=2-2]
\end{tikzcd}\]
        Consider \( Z \subseteq \mathbb A^2_k = \Spec k[x,y] \) given by the vanishing locus of \( xy - 1 \).
        Then the projection of \( Z \) onto each axis is not Zariski closed.
        \item The bug-eyed line is neither separated nor universally closed.
    \end{enumerate}
\end{example}
\begin{remark}
	If \( X \to S \) is universally closed, then any base extension \( X \times_S S' \to S' \) is also universally closed.
    Similarly, separatedness, properness and being of finite type are stable under base extension.
\end{remark}
\begin{proposition}
    Let \( R \) be a commutative ring.
    Then the morphism \( \mathbb P^n_R \to \Spec R \) is proper.
\end{proposition}
\begin{proof}
    We have already shown that \( \mathbb P^n_R \to \Spec R \) is separated.
    It is of finite type by construction.
    It suffices to prove that the morphism is universally closed for \( R = \mathbb Z \), because \( \mathbb P^n_R = \mathbb P^n_{\mathbb Z} \times_{\Spec \mathbb Z} \Spec R \).
    We must show that for any \( Y \to \Spec \mathbb Z \), the base extension \( \mathbb P^n_{\mathbb Z} \times_{\Spec \mathbb Z} Y \to Y \) is closed.
    But \( Y \) is covered by affine schemes of the form \( \Spec R \), and closedness is local on the codomain, it suffices to show that \( \mathbb P^n_R \to \Spec R \) is closed.

    Let \( Z \subseteq \mathbb P^n_R \) be Zariski closed, so \( Z \) is the vanishing locus of homogeneous polynomials \( \qty{g_1, g_2, \dots} \).
    We want to show that if \( \pi \) is the map \( \mathbb P^n_R \to \Spec R \), then \( \pi(Z) \) is closed.
    We need to find equations for \( \pi(Z) \), or equivalently, we need to characterise the prime ideals \( \mathfrak p \) of \( R \) such that \( \pi^{-1}(\mathfrak p) \cap Z \) is nonempty.
    Let \( k(\mathfrak p) = FF\qty(\faktor{R}{\mathfrak p}) \).
    We have a morphism \( \Spec k(\mathfrak p) \to \Spec R \).
    Let \( Z_{\mathfrak p} = Z \times_{\Spec R} \Spec k(\mathfrak p) \); we want to know for which \( \mathfrak p \) this scheme is nonempty.
    If we take the equations \( g_1, g_2, \dots \) and reduce modulo \( \mathfrak p \), we obtain equations \( \overline g_1, \overline g_2, \dots \) which are homogeneous polynomials in \( k(\mathfrak p) \).
    Thus \( Z_{\mathfrak p} \) is nonempty if and only if \( \overline g_1, \overline g_2, \dots \) cut out more than the origin in \( \mathbb A^{n+1}_{k(\mathfrak p)} \).
    In particular, \( Z_{\mathfrak p} \) is nonempty if and only if
    \[ \sqrt{(\overline g_1, \overline g_2, \dots)} \nsupseteq (x_0, \dots, x_n);\quad \mathbb P^n_R = \Proj R[x_0, \dots, x_n] \]
    Equivalently, for all positive integers \( d \),
    \[ (x_0, \dots, x_n)^d \nsubseteq (\overline g_1, \overline g_2, \dots) \]
    Write \( A = R[\vb x] \) with the usual grading.
    The non-containment condition above holds if and only if the map
    \[ \bigoplus_i A_{d - \deg g_i} \to A_d \]
    given by \( f_i \mapsto f_i g_i \) in the \( i \)th factor is not surjective modulo \( \mathfrak p \), or equivalently in \( k(\mathfrak p) \), for all degrees \( d \).
    This condition is given by the maximal minors of the matrix associated to \( \bigoplus_i A_{d - \deg g_i} \to A_d \), which is a set of infinitely many polynomials, each in the coefficients of the \( g_i \).
\end{proof}

\subsection{Valuative criteria}
From here, we will assume that all schemes are Noetherian; that is, it has a finite cover by spectra of Noetherian rings.
\begin{definition}
    A \emph{discrete valuation ring} is a local principal ideal domain.
\end{definition}
\begin{example}
    \begin{enumerate}
        \item \( \mathbb C\Brackets{t} \) is a discrete valuation ring.
        \item \( \mathcal O_{\mathbb A^1, 0} = \qty{\frac{f(t)}{g(t)} \midd g(0) \neq 0} \) is a discrete valuation ring.
        \item Similarly, \( \mathbb Z_{(p)}, \mathbb Z_p \) are discrete valuation rings, where \( \mathbb Z_{(p)} \) denotes the localisation of \( \mathbb Z \) at the prime ideal \( (p) \), and \( \mathbb Z_p \) denotes the \( p \)-adic integers.
    \end{enumerate}
\end{example}
We will often drop the word `discrete'.
\begin{remark}
    Let \( A \) be a valuation ring.
    In discrete valuation rings, every nonzero prime ideal is maximal, so \( \Spec A \) consists of two points, \( (0) \) and the unique maximal ideal \( \mathfrak m \).
    The topology on \( \Spec A = \qty{(0), \mathfrak m} \) has the property that \( (0) \) is dense and \( \mathfrak m \) is closed.
    This is called the \emph{Sierpi\'nski topology}.

    Any generator \( \pi \) for \( \mathfrak m \) is called a \emph{uniformiser} or a \emph{uniformising parameter}.
    For example, in \( \mathbb C\Brackets{t} \), every power series with nonzero constant term is a unit, and \( t \) is a uniformiser.

    Given a uniformiser, any nonzero element \( a \in A \) can be written as \( u \pi^k \) where \( u \) is a unit and \( k \) is a unique natural number called the \emph{valuation} of \( a \).
    This gives a map \( A \setminus \qty{0} \to \mathbb N \) mapping a value \( a \) to its valuation; this is independent of the choice of uniformiser.

    The field of fractions of \( A \) is a \emph{valued field} \( K = FF(A) \); the valuation extends to a multiplicative function \( K \setminus \qty{0} \to \mathbb Z \) given by the difference of valuations of the numerator and denominator.
\end{remark}
\begin{example}
    Let \( A = k\Brackets{t} \), then \( K = k\lParen t\rParen \) is the field of Laurent series in one variable in \( k \).
    The valuation is the order of vanishing at zero.
\end{example}
One can consider the open immersion \( \Spec K \to \Spec A \) as the inclusion from a disc with a punctured origin to a disc.
\begin{theorem}
    Let \( f : X \to Y \) be a morphism of schemes.
    Then \( f \) is separated if and only if for any (discrete) valuation ring \( A \) with function field \( K \) and diagram
    % https://q.uiver.app/#q=WzAsNCxbMCwwLCJcXFNwZWMgSyJdLFsxLDAsIlgiXSxbMSwxLCJZIl0sWzAsMSwiXFxTcGVjIEEiXSxbMCwxXSxbMSwyXSxbMCwzXSxbMywyXV0=
\[\begin{tikzcd}
	{\Spec K} & X \\
	{\Spec A} & Y
	\arrow[from=1-1, to=1-2]
	\arrow[from=1-2, to=2-2]
	\arrow[from=1-1, to=2-1]
	\arrow[from=2-1, to=2-2]
\end{tikzcd}\]
    then there exists at most one lift \( \Spec A \to X \) that makes the following diagram commute.
    % https://q.uiver.app/#q=WzAsNCxbMCwwLCJcXFNwZWMgSyJdLFsxLDAsIlgiXSxbMSwxLCJZIl0sWzAsMSwiXFxTcGVjIEEiXSxbMCwxXSxbMSwyXSxbMCwzXSxbMywyXSxbMywxLCIiLDEseyJzdHlsZSI6eyJib2R5Ijp7Im5hbWUiOiJkYXNoZWQifX19XV0=
\[\begin{tikzcd}
	{\Spec K} & X \\
	{\Spec A} & Y
	\arrow[from=1-1, to=1-2]
	\arrow[from=1-2, to=2-2]
	\arrow[from=1-1, to=2-1]
	\arrow[from=2-1, to=2-2]
	\arrow[dashed, from=2-1, to=1-2]
\end{tikzcd}\]
    Similarly, \( f \) is universally closed if and only if there exists at least one lift \( \Spec A \to X \) that makes the diagram commute.
\end{theorem}
In particular, a morphism is proper if and only if there is a unique lift, and the morphism is of finite type.
The proof is omitted.
\begin{remark}
    \begin{enumerate}
        \item The map \( \mathbb P^n_R \to \Spec R \) is proper.
        \item The map \( \mathbb A^n_R \to \Spec R \) is not proper, but is separated.
        \item Closed immersions are proper.
        In particular, if \( Z \to \mathbb P^n_R \) is closed, then \( Z \to \Spec R \) is proper.
        \item Compositions of proper (respectively separated) morphisms are proper (separated).
        \item If \( f : X \to Y \) is proper, then for any \( Y' \to Y \), the base extension \( X \times_Y Y' \to Y' \) is also proper.
    \end{enumerate}
\end{remark}
\begin{example}
    We show that \( \mathbb A^1_k \to \Spec k \) is not proper by showing it is not universally closed.
    Write \( \mathbb A^1_k = \Spec k[x] \), and consider \( A = k\Brackets{t} \) and \( K = k\lParen t\rParen \).
    % https://q.uiver.app/#q=WzAsNCxbMCwwLCJcXFNwZWMga1xcbFBhcmVuIHRcXHJQYXJlbiJdLFsxLDAsIlxcbWF0aGJiIEFeMV9rIl0sWzEsMSwiXFxTcGVjIGsiXSxbMCwxLCJcXFNwZWMga1xcQnJhY2tldHN7dH0iXSxbMCwxLCJcXHZhcnBoaSJdLFsxLDJdLFswLDNdLFszLDJdXQ==
\[\begin{tikzcd}
	{\Spec k\lParen t\rParen} & {\mathbb A^1_k} \\
	{\Spec k\Brackets{t}} & {\Spec k}
	\arrow["\varphi", from=1-1, to=1-2]
	\arrow[from=1-2, to=2-2]
	\arrow[from=1-1, to=2-1]
	\arrow[from=2-1, to=2-2]
\end{tikzcd}\]
    The map \( \Spec k\Brackets{t} \to \Spec k \) is the obvious morphism.
    Let \( \varphi \) be induced by the map on rings \( k[x] \to k\lParen t \rParen \) given by \( x \mapsto \frac{1}{t} \).
    Then the map does not factor through \( \Spec k\Brackets{t} \to \Spec k\lParen t \rParen \), as required.
    However, if we replace \( \mathbb A^1_k \) with \( \mathbb P^1_k \), there is always an affine chart in \( \mathbb P^1 \) such that \( \varphi \) is of the form \( x \mapsto t \).
\end{example}
